package com.fdb.efp.cus.service.impl;

import com.fdb.efp.cus.service.dao.CusHitCaseInfoDao;
import com.fdb.efp.cus.service.domain.CusHitCaseInfo;
import com.gdrcu.efp.cus.common.CusConstant;
import com.fdb.basic.framework.core.base.AbstractFrameworkService;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.basic.framework.core.constant.SequenceConstance;
import com.fdb.basic.framework.core.vo.CusHandOverVO;
import com.fdb.efp.cus.service.facade.CusHitCaseInfoService;
import com.fdb.efp.cus.service.vo.CusHitCaseInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 客户移交申请
 * <p>
 * 
 * @author chenqm1
 * @date 2018-05-14
 */
@Service("cusHitCaseInfoService")
public class CusHitCaseInfoServiceImpl extends AbstractFrameworkService implements CusHitCaseInfoService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(CusHitCaseInfoServiceImpl.class);

	@Autowired
	private CusHitCaseInfoDao cusHitCaseInfoDao;


	@SuppressWarnings("unchecked")
	public int insertCusHitCaseInfo(CusHitCaseInfoVO cusVo) throws Exception{
		logger.info("新增名单系统命中案例数据开始");
		int num = 0;
		try {
			CusHitCaseInfo cus = new CusHitCaseInfo();
			beanCopy(cusVo, cus);
			num=cusHitCaseInfoDao.insertCusHitCaseInfo(cus);

		} catch (Exception e) {
			String errorMsg="新增【名单系统命中案例数据】表异常："+e.getMessage();
			logger.error(errorMsg);
			num=-1;
			throw new Exception(errorMsg);
		}
        return num;
	}

	@SuppressWarnings("unchecked")
	public int updateCusHitCaseInfo(CusHitCaseInfoVO cusVo) throws Exception{
		logger.info("更新名单系统命中案例数据开始");
		int num = 0;
		try {
			CusHitCaseInfo cus = new CusHitCaseInfo();
			beanCopy(cusVo, cus);
			num=cusHitCaseInfoDao.updateCusHitCaseInfo(cus);
		} catch (Exception e) {
			String errorMsg="更新【名单系统命中案例数据】表异常："+e.getMessage();
			logger.error(errorMsg);
			num=-1;
			throw new Exception(errorMsg);
		}
		return num;
	}

	@SuppressWarnings("unchecked")
	public List<CusHitCaseInfoVO> queryAll() throws Exception{
		logger.info("查询名单系统命中案例数据表开始");
		List<CusHitCaseInfoVO> list = null;
		try {
			List<CusHitCaseInfo> cusHitCaseInfoList=cusHitCaseInfoDao.queryAll();
			list = (List<CusHitCaseInfoVO>) beansCopy(cusHitCaseInfoList, CusHitCaseInfoVO.class);
		} catch (Exception e) {
			String errorMsg="【名单系统命中案例数据】表数据转换出现异常!："+e.getMessage();
			logger.error(errorMsg);
			throw new Exception(errorMsg);
		}
		return list;
	}
	@SuppressWarnings("unchecked")
	public CusHitCaseInfoVO queryByPart(CusHitCaseInfoVO cusVo) throws Exception{
		logger.info("查询名单系统命中案例数据表开始");
		try {
			CusHitCaseInfo cus = new CusHitCaseInfo();
			beanCopy(cusVo, cus);
			CusHitCaseInfo queryCus=cusHitCaseInfoDao.queryByPart(cus);
			if (Objects.nonNull(queryCus)) {
				CusHitCaseInfoVO OutCusVo = beanCopy(cus, new CusHitCaseInfoVO());
				logger.info("当前查询结果为："+OutCusVo.toString());
				return OutCusVo;
			}else {
				logger.info("当前查询结果为空");
			}
		} catch (Exception e) {
			String errorMsg="【名单系统命中案例数据】表数据转换出现异常!："+e.getMessage();
			logger.error(errorMsg);
			throw new Exception(errorMsg);
		}
		return null;
	}

}
